<template>
	<view>
		<u-popup :show="tdeng" round="35rpx" :safeAreaInsetBottom="false">
			<view style="padding: 60rpx 25rpx">
				<view class="" style="font-weight: bold; font-size: 40rpx; color: #222222">欢迎使用小易家装网</view>
				<view class="" style="margin-top: 20rpx; font-weight: 500; font-size: 24rpx; color: #888888">建议使用您的微信头像和昵称，以便获得更好的体验。</view>
				<view class="" style="display: flex; justify-content: center">
					<view style="padding: 33rpx 184rpx; background: linear-gradient(90deg, #ff0c09 0%, #e00500 100%); border-radius: 49rpx; margin-top: 111rpx; position: relative">
						<button open-type="getPhoneNumber" @getphonenumber="getphonenumber" style="position: absolute; top: 10rpx; width: 100%; left: 0; opacity: 0">12</button>
						<view class="" style="font-weight: bold; font-size: 33rpx; color: #ffffff">手机号一键登录</view>
					</view>
				</view>
				<view class=" " style="margin-top: 30rpx; text-align: center; font-weight: 500; font-size: 26rpx; color: #888888" @click="tiao">暂时跳过</view>
				<view class="" style="display: flex; margin-top: 80rpx">
					<view class="" style="margin-left: 56rpx">
						<u-checkbox-group activeColor="#FF0300" v-model="checkboxValue1">
							<u-checkbox name="1"></u-checkbox>
							<text style="font-size: 29rpx">
								我已阅读并同意
								<text style="color: #ff0300; text-decoration: underline; margin-left: 5rpx" @click="yonghu">用户协议</text>
								和
								<text style="color: #ff0300; text-decoration: underline; margin-left: 5rpx" @click="yinsi">隐私政策</text>
							</text>
						</u-checkbox-group>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
import { userbindMobile, usermobilelogin } from '../../untils/api.js';
export default {
	name: 'uni-login',
	data() {
		return {
			tdeng: this.$store.state.td,
			checkboxValue1: ['1']
		};
	},
	watch: {
		'$store.state.td': function (newVal) {
			this.tdeng = newVal; // 更新组件中的 tdeng
		}
	},
	methods: {
		tiao() {
			this.$store.commit('tf');
		},
		async getphonenumber(e) {
			console.log(e.detail.code);
			const data1 = await userbindMobile({
				code: e.detail.code
			});
			uni.login({
				provider: 'weixin',
				onlyAuthorize: true, // 微信登录仅请求授权认证
				success: async (event) => {
					console.log(event.code);
					const { data: denglu } = await usermobilelogin({
						wechat_code: event.code,
						pid: uni.getStorageSync('pid'),
						mobile: data1.data.mobile
					});
					console.log(denglu);
					uni.setStorageSync('token', denglu.token);
					uni.setStorageSync('userid', denglu.id);
					this.$store.commit('tf');
					uni.reLaunch({
						url: '/pages/index/index'
					});
				},
				fail: function (err) {
					console.log(err);
				}
			});
		}
	}
};
</script>

<style></style>
